using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Koda.VisualStudio;
using Koda.Utils;
using Koda.Model;

namespace Koda.UI
{
    public partial class GeneratePropertiesForm : Form
    {
        private PropertyGenerator propertyGenerator;

        public GeneratePropertiesForm(PropertyGenerator propertyGenerator)
        {
            if (propertyGenerator == null)
                throw new ArgumentNullException("propertyGenerator");

            this.propertyGenerator = propertyGenerator;
            this.AutoScaleMode = AutoScaleMode.None;
            this.Font = SystemFonts.MessageBoxFont;
            this.AutoScaleMode = AutoScaleMode.Font;

            this.InitializeComponent();
        }

        private void PropertiesForm_Load(object sender, EventArgs e)
        {
            NameValueCollection collection = new NameValueCollection();
            collection.Add("Public", EnvDTE.vsCMAccess.vsCMAccessPublic);
            collection.Add("Private", EnvDTE.vsCMAccess.vsCMAccessPrivate);
            collection.Add("Protected", EnvDTE.vsCMAccess.vsCMAccessProtected);

            NameValueCollection propertyOptions = new NameValueCollection();
            propertyOptions.Add("None", PropertyOptions.None);
            propertyOptions.Add("Get and Set", PropertyOptions.GetSet);
            propertyOptions.Add("Get", PropertyOptions.Get);
            propertyOptions.Add("Set", PropertyOptions.Set);

            this.nameValueItemBindingSource1.DataSource = propertyOptions;
            this.nameValueItemBindingSource.DataSource = collection;
            this.propertyBindingSource.DataSource = this.propertyGenerator.Properties;
            this.propertyGenerator.SelectAllNonExisting();
        }

        private void acceptButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.propertyGenerator.Generate();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void selectAllButton_Click(object sender, EventArgs e)
        {
            this.propertyGenerator.SelectAll();
        }

        private void selectNoneButton_Click(object sender, EventArgs e)
        {
            this.propertyGenerator.SelectNone();
        }

        private void selectAllGetButton_Click(object sender, EventArgs e)
        {
            this.propertyGenerator.SelectAllGetters();
        }

        private void selectAllSetButton_Click(object sender, EventArgs e)
        {
            this.propertyGenerator.SelectAllSetters();
        }

        private void selectAllMissingButton_Click(object sender, EventArgs e)
        {
            this.propertyGenerator.SelectAllNonExisting();
        }
    }
}